import com.sun.org.apache.xpath.internal.objects.XNull;

import java.util.Random;
import java.util.Scanner;

public class GessNumber {

    public static void main(String[] args) {
        Random r = new Random();
        int num ;
        Scanner scan = new Scanner(System.in);
        while (true) {
            num = r.nextInt(100) + 1;
            for (int i = 1; i < 8; i++) {
                System.out.println("请输入你猜的数字：");
                int gessnum = scan.nextInt();
                if (i == 7) {
                    System.out.println("已经猜了7次");
                    System.out.println("正确答案是：" + num + "游戏结束");

                } if (gessnum > num) {
                    System.out.println("你猜得太大了！请重试");
                } else if (gessnum < num) {
                    System.out.println("你猜得太小了！请重试");
                } else {
                    System.out.println("恭喜你，你猜对啦！");
                    break;
                }

            }
            System.out.println("再玩一次嘛？(y/n)");
            String again = scan.next();
            if (!again.equalsIgnoreCase("y")) {
                break;
            }
        } System.out.println("游戏结束。");
    }
}